package com.diudiutechnology.www.yadiudiu.util.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import com.diudiutechnology.www.yadiudiu.yadiudiu.model.MineFragmentModel;

/**
 * Created by Administrator on 2017/9/5.
 */

public class UserInfoUtils {
    private static final String isLogin = "false";
    private static final String id = "id";
    private static final String avatar = "avatar";
    private static final String nickname = "nickname";
    private static final String password = "password";
	private static final String phone = "phone";
	private static final String balance = "balance";
	private static final String redenvelope = "redenvelope";
	private static final String points = "points";
	private static final String creditscore = "creditscore";
	private static final String creditrating = "creditrating";
	private static final String currentprovince = "currentprovince";
    private static final String currentcity = "currentcity";
    private static final String currentdist = "currentdist";
    private static final String currentsuite = "currentsuite";
    private static final String is_educationcerti = "is_educationcerti";
    private static final String realname = "realname";
    private static final String idcardno = "idcardno";
    private static final String frontofidcard = "frontofidcard";
    private static final String idcardnegative = "idcardnegative";
    private static final String drivinglicense = "drivinglicense";
    private static final String drivinglicenseback = "drivinglicenseback";
    private static final String drivingpermitface = "drivingpermitface";
    private static final String driveback = "driveback";
    private static final String education = "education";
    private static final String bankNumber = "bankNumber";
    private static final String addresscount = "addresscount";
    private static final String toexamine = "toexamine";
    private static final String merchanttype = "merchanttype";

    private static UserInfoUtils userInfoSing = null;
    public  UserInfoUtils(){

    }

    public static UserInfoUtils getInstans() {
        if (userInfoSing == null) {
            userInfoSing = new UserInfoUtils();
        }
        return userInfoSing;
    }

    MineFragmentModel user;
//缓存
    public void writeUserInfo(Context context, MineFragmentModel user) {
        this.user=user;
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
        SharedPreferences.Editor editor = sp.edit();
        editor.putBoolean(isLogin, true);
        editor.putString(id, user.getId());
        editor.putString(avatar, user.getAvatar());
		editor.putString(nickname, user.getNickname());
        editor.putString(password, user.getPassword());

		editor.putString(phone, user.getPhone());
		editor.putString(balance, user.getBalance());
		editor.putString(redenvelope, user.getRedenvelope());
		editor.putString(points, user.getPoints());
		editor.putString(creditscore, user.getCreditscore());
		editor.putString(creditrating, user.getCreditrating());
		editor.putString(currentprovince, user.getCurrentprovince());
        editor.putString(currentcity, user.getCurrentcity());
        editor.putString(currentdist, user.getCurrentdist());
        editor.putString(currentsuite, user.getCurrentsuite());
        editor.putString(is_educationcerti, user.getIs_educationcerti());
        editor.putString(realname, user.getRealname());
        editor.putString(idcardno, user.getIdcardno());
        editor.putString(frontofidcard, user.getFrontofidcard());
        editor.putString(idcardnegative, user.getIdcardnegative());
        editor.putString(drivinglicense, user.getDrivinglicense());
        editor.putString(drivinglicenseback, user.getDrivinglicenseback());
        editor.putString(drivingpermitface, user.getDrivingpermitface());
        editor.putString(driveback, user.getDriveback());
        editor.putString(education, user.getEducation());
        editor.putString(bankNumber, user.getBankNumber());
        editor.putString(addresscount, user.getAddresscount());
        editor.putString(toexamine, user.getToexamine());
        editor.putString(merchanttype, user.getMerchanttype());

        editor.apply();
    }

    //调用的
    public static MineFragmentModel readUserInfo(Context context) {
        MineFragmentModel userInfo = new MineFragmentModel();
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
        userInfo.setId(sp.getString(id, ""));
        userInfo.setAvatar(sp.getString(avatar, ""));
		userInfo.setNickname(sp.getString(nickname, ""));
        userInfo.setPassword(sp.getString(password, ""));

		userInfo.setPhone(sp.getString(phone, ""));
		userInfo.setBalance(sp.getString(balance, ""));
		userInfo.setRedenvelope(sp.getString(redenvelope, ""));
		userInfo.setPoints(sp.getString(points, ""));
		userInfo.setCreditscore(sp.getString(creditscore, ""));
		userInfo.setCreditrating(sp.getString(creditrating, ""));
		userInfo.setCurrentprovince(sp.getString(currentprovince, ""));
        userInfo.setCurrentcity(sp.getString(currentcity, ""));
        userInfo.setCurrentdist(sp.getString(currentdist, ""));
        userInfo.setCurrentsuite(sp.getString(currentsuite, ""));
        userInfo.setIs_educationcerti(sp.getString(is_educationcerti, ""));
        userInfo.setRealname(sp.getString(realname, ""));
        userInfo.setIdcardno(sp.getString(idcardno, ""));
        userInfo.setFrontofidcard(sp.getString(frontofidcard, ""));
        userInfo.setIdcardnegative(sp.getString(idcardnegative, ""));
        userInfo.setDrivinglicense(sp.getString(drivinglicense, ""));
        userInfo.setDrivinglicenseback(sp.getString(drivinglicenseback, ""));
        userInfo.setDrivingpermitface(sp.getString(drivingpermitface, ""));
        userInfo.setDriveback(sp.getString(driveback, ""));
        userInfo.setEducation(sp.getString(education, ""));
        userInfo.setBankNumber(sp.getString(bankNumber, ""));
        userInfo.setAddresscount(sp.getString(addresscount, ""));
        userInfo.setToexamine(sp.getString(toexamine, ""));
        userInfo.setMerchanttype(sp.getString(merchanttype, ""));

        return userInfo;
    }

    /**
     * 修改电话
     */
    public void updatephone(Context context,String phone) {

        user.setPhone(phone);
        userInfoSing.writeUserInfo(context,user);
    }

    /**
     * 修改昵称
     */
    public void updatename(Context context,String name) {
        //修改昵称
        user.setNickname(name);
        userInfoSing.writeUserInfo(context,user);
    }
    /**
     * 修改头像
     */
    public void updateavatar(Context context,String avatar) {

        user.setAvatar(avatar);
        userInfoSing.writeUserInfo(context,user);
    }
    /**
     * 修改身份证正面
     */
    public void updatefrontofidcard(Context context,String frontofidcard) {

        user.setFrontofidcard(frontofidcard);
        userInfoSing.writeUserInfo(context,user);
    }
    /**
     * 修改身份反正面
     */
    public void updateIdcardnegative(Context context,String idcardnegative) {

        user.setIdcardnegative(idcardnegative);
        userInfoSing.writeUserInfo(context,user);
    }
    /**
     * 修改银行卡数量
     */
    public void updatebankNumber(Context context,String bankNumber) {

        user.setBankNumber(bankNumber);
        userInfoSing.writeUserInfo(context,user);
    }
    /**
     * 修改学历认证
     */
    public void updateis_educationcerti(Context context,String is_educationcerti) {

        user.setIs_educationcerti(is_educationcerti);
        userInfoSing.writeUserInfo(context,user);
    }
    /**
     * 修改驾驶证正面
     */
    public void updatedrivinglicense(Context context,String drivinglicense) {

        user.setDrivinglicense(drivinglicense);
        userInfoSing.writeUserInfo(context,user);
    }
    /**
     * 修改驾驶证反面
     */
    public void updatedrivinglicenseback(Context context,String drivinglicenseback) {

        user.setDrivinglicenseback(drivinglicenseback);
        userInfoSing.writeUserInfo(context,user);
    }

    /**
     * 修改行驶证正面
     */
    public void updatedrivingpermitface(Context context,String drivingpermitface) {

        user.setDrivingpermitface(drivingpermitface);
        userInfoSing.writeUserInfo(context,user);
    }
    /**
     * 修改驾驶证反面
     */
    public void updatedriveback(Context context,String driveback) {

        user.setDriveback(driveback);
        userInfoSing.writeUserInfo(context,user);
    }
    /**
     * 修改详细地址
     */
    public void updateCurrentsuite(Context context,String Currentsuite) {

        user.setCurrentsuite(Currentsuite);
        userInfoSing.writeUserInfo(context,user);
    }
}
